<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:name}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFiveShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem" >
            <p class="analyItemTit tx-center">交底描述</p>
            <div class="analyItemCon">
                <div class="clearfix">
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 4, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer v-for="(item, index) of safeDateList" :key="index" class="mr10 fl">
                        <div class="look_imgHover fl relative" style="width:78px;height:78px;" >
                            <img :src="item">
                            <div class="upload_finish_div" v-if="buttonIsShow">
                                <div class="upload_finish_bg"></div>
                                <div class="upload_finish_linksm">
                                    <div class="dis-il-block">
                                        <a href="javascript:" class="ImgBtn enlarge_viewer enlarge_link" :data-src="item"></a>
                                        <a href="javascript:" class="ImgBtn delect_link" @click="delectImg(index)"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>
                </div>
                <div class="mt10">
                    <textarea placeholder="请输入交底描述" class="col-md-11" v-model="text"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="submitButton()" v-if="buttonIsShow">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getSafetyConfide, safeUploadPhoto } from '../../../../Resources/Api/scene'
export default {
    props: ['titleName', 'url', 'type'],
    data () {
        return {
            safeCloseData: null, // 现场交底数据
            text: '', // 交底描述
            name: '',
            safeDateList: [], // 图片集合
            buttonIsShow: false // 按钮是否显示
        }
    },
    computed: {
        ...mapGetters(['updatePlate', 'twoToThreeInfo', 'userInfo'])
    },
    created () {
        this.name = this.titleName
        this.getSafetyConfide()
        this.buttonType()
    },
    methods: {
        buttonType () {
            if (this.twoToThreeInfo.status === this.type) {
                this.buttonIsShow = true
            } else {
                const userLevel = this.userInfo.as_level
                if (userLevel.length > 0) {
                    userLevel.forEach(ele => {
                        if (Number(ele) === 82 || Number(ele) === 83) {
                            if (this.twoToThreeInfo.status === this.type) {
                                this.buttonIsShow = true
                            } else {
                                this.buttonIsShow = false
                            }
                        } else if (Number(ele) === 47) {
                            if (Number(this.userInfo.as_cardNo) === Number(this.leftInfo.supervisor_userno)) {
                                if (this.twoToThreeInfo.status === this.type) {
                                    this.buttonIsShow = true
                                } else {
                                    this.buttonIsShow = false
                                }
                            } else {
                                this.buttonIsShow = false
                            }
                        } else {
                            this.buttonIsShow = false
                        }
                    })
                } else {
                    this.buttonIsShow = false
                }
            }
        },
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 上传图片
        successUpload (value) {
            this.safeDateList.push(value.src)
        },
        // 删除图片
        delectImg (index) {
            this.safeDateList.splice(index, 1)
        },
        // 获取交底数据
        getSafetyConfide () {
            let parms = {
                orderCode: this.$route.query.code
            }
            getSafetyConfide(parms).then(results => {
                if (results.data.StatusCode === 1) {
                    if (results.data.Body.safetyConfideOrder !== null) {
                        this.safeCloseData = results.data.Body.safetyConfideOrder
                        if (this.safeCloseData.img !== '') {
                            this.safeDateList = this.safeCloseData.img.split(',')
                        }
                        this.text = results.data.Body.safetyConfideOrder.content
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 提交数据
        submitButton () {
            if (this.safeDateList.length === 0) {
                return false
            }
            let parm = {
                id: this.safeCloseData.id,
                img: this.safeDateList.length > 0 ? this.safeDateList.join(',') : '',
                content: this.text,
                orderCode: this.$route.query.code,
                userNo: this.userInfo.as_cardNo,
                userName: this.userInfo.as_fullName
            }
            // const dataJson = JSON.stringify(parm)
            safeUploadPhoto(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFiveShow()
                }
            }).catch(error => {
                console.log(error)
            })
        }
    },
    watch: {
        $route () {
            this.safeGetPhoto()
        }
    }
}
</script>
<style lang="">
    .fixedBox {
        display: flex;
        align-items: center;
    }
</style>
